﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GreatB2C.Config.SiteInfo;

namespace GreatB2C.Web.Manage.SystemSet.SiteInfo
{
    public partial class SMSSet : Inherit.ManagePage
    {
        protected void Page_Load( object sender , EventArgs e )
        {
            if ( !IsPostBack )
            {
                LoadSetting( );
            }
        }

        protected void LoadSetting( )
        {
            txtUserName.Text = SMSConfig.UserName.ToString( );
            txtMD5Key.Text = SMSConfig.MD5Key.ToString( );
            radlIsAutoSend.SelectedValue = SMSConfig.IsAutoSend.ToString( );
            txtAdminPhoneNumber.Text = SMSConfig.AdminPhoneNumber.ToString( );
            txtOrderMessage.Text = SMSConfig.OrderMessage.ToString( );
            radlIsAutoSendCardNumber.SelectedValue = SMSConfig.IsAutoSendCardNumber.ToString( );
            txtConfirmOrderMessage.Text = SMSConfig.ConfirmOrderMessage.ToString( );
            txtRemitMessage.Text = SMSConfig.RemitMessage.ToString( );
            txtRefundmentMessage.Text = SMSConfig.RefundmentMessage.ToString( );
            txtInvoiceMessage.Text = SMSConfig.InvoiceMessage.ToString( );
            txtConsignmentMessage.Text = SMSConfig.ConsignmentMessage.ToString( );
            txtSendCardNumberMessage.Text = SMSConfig.SendCardNumberMessage.ToString( );
            txtUseLabel.Text = SMSConfig.UseLabel.ToString( );
            txtCartInformMessage.Text = SMSConfig.CartInformMessage.ToString( );
            txtBankLogMessage.Text = SMSConfig.BankLogMessage.ToString( );
            txtIncomeLogMessage.Text = SMSConfig.IncomeLogMessage.ToString( );
            txtPayoutLogMessage.Text = SMSConfig.PayoutLogMessage.ToString( );
            txtExchangePointMessage.Text = SMSConfig.ExchangePointMessage.ToString( );
            txtEncouragePointMessage.Text = SMSConfig.EncouragePointMessage.ToString( );
            txtPayoutPointMessage.Text = SMSConfig.PayoutPointMessage.ToString( );
            txtExchangePeriodMessage.Text = SMSConfig.ExchangePeriodMessage.ToString( );
            txtEncouragePeriodMessage.Text = SMSConfig.EncouragePeriodMessage.ToString( );
            txtPayoutPeriodMessage.Text = SMSConfig.PayoutPeriodMessage.ToString( );
            txtCouponMessage.Text = SMSConfig.CouponMessage.ToString( );
            radlIsAutoSendStateMessage.SelectedValue = SMSConfig.IsAutoSendStateMessage.ToString( );
            txtChangeStateMessage.Text = SMSConfig.ChangeStateMessage.ToString( );
            txtOutOfLogSmsConfig.Text = SMSConfig.OutOfLogSmsConfig.ToString( );
        }

        protected void BtnSubmit_Click( object sender , EventArgs e )
        {
            bool isSuccess = SMSConfig.Config( txtUserName.Text.Trim( ) , txtMD5Key.Text.Trim( ) , radlIsAutoSend.SelectedValue.ToString( ) , txtAdminPhoneNumber.Text.Trim( )
            , txtOrderMessage.Text.Trim( ) , radlIsAutoSendCardNumber.SelectedValue.ToString( ) , txtConfirmOrderMessage.Text.Trim( ) , txtRemitMessage.Text.Trim( )
            , txtRefundmentMessage.Text.Trim( ) , txtInvoiceMessage.Text.Trim( ) , txtConsignmentMessage.Text.Trim( ) , txtSendCardNumberMessage.Text.Trim( )
            , txtUseLabel.Text.Trim( ) , txtCartInformMessage.Text.Trim( ) , txtBankLogMessage.Text.Trim( ) , txtIncomeLogMessage.Text.Trim( )
            , txtPayoutLogMessage.Text.Trim( ) , txtExchangePointMessage.Text.Trim( ) , txtEncouragePointMessage.Text.Trim( ) , txtPayoutPointMessage.Text.Trim( )
            , txtExchangePeriodMessage.Text.Trim( ) , txtEncouragePeriodMessage.Text.Trim( ) , txtPayoutPeriodMessage.Text.Trim( ) , txtCouponMessage.Text.Trim( )
            , radlIsAutoSendStateMessage.SelectedValue.ToString( ) , txtChangeStateMessage.Text.Trim( ) , txtOutOfLogSmsConfig.Text.Trim( ) );

            if ( isSuccess )
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "手机短信配置成功！" ) + "&rtn=SystemSet/SiteInfo/SMSSet.aspx" );
            }
            else
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "手机短信配置失败，请联系管理员！" ) + "&rtn=SystemSet/SiteInfo/SMSSet.aspx" );
            }
        }
    }
}
